//GetPostServletTest.java
package com.ylaihui.servlet;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.nio.IntBuffer;

public class GetPostServletTest implements Servlet {
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        //System.out.println(servletRequest.getClass());  // class org.apache.catalina.connector.RequestFacade

        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;

        String method = httpServletRequest.getMethod();

        if ("GET".equals(method)) {
            doGet();
        }else if("POST".equals(method)){
            doPost();
        }

    }

    private void doPost() {
        System.out.println("post request!");
    }

    private void doGet() {
        System.out.println("get request!");
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
